#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""DocString

DocString Paragraph

"""
import MySQLdb
import sys

def connect( USER = '', PASSWD = '', DB = '', HOST = ''):
    conn = MySQLdb.connect (host = HOST,
        user = USER,
        passwd = PASSWD,
        db = DB)
    return conn

def version(conn):
    cursor = conn.cursor ()
    cursor.execute ("SELECT VERSION()")
    row = cursor.fetchone ()
    print "server version:", row[0]
    cursor.close ()

def select(conn, sql):
    cursor = conn.cursor (MySQLdb.cursors.DictCursor)
    cursor.execute (sql)
    rows = cursor.fetchall ()
    cursor.close ()
    return rows

def execute(conn, sql):
    try: 
        cursor = conn.cursor (MySQLdb.cursors.DictCursor)
        cursor.execute (sql)
        cursor.close ()
        return cursor.rowcount
    except:
        print "Unexpected error:", sys.exc_info()

def close(conn):
    conn.close ()

__version__ = "$Revision$"
# $Source$


